package com.ruoyi.web.controller.substation;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SParameterDetailsRemarks;
import com.ruoyi.system.domain.vo.ParameterDetailsHistoryParamsVo;
import com.ruoyi.system.service.ISParameterDetailsRemarksService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SParameterDetails;
import com.ruoyi.system.service.ISParameterDetailsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 参数详情Controller
 * 
 * @author ruoyi
 * @date 2023-07-05
 */
@Api(tags = "参数详情管理")
@RestController
@RequestMapping("/substation/parameterDetails")
public class SParameterDetailsController extends BaseController
{
    @Autowired
    private ISParameterDetailsService sParameterDetailsService;

    @Autowired
    private ISParameterDetailsRemarksService sParameterDetailsRemarksService;
    /**
     * 查询参数详情列表
     */
    @ApiOperation("获取参数详情列表")
    @PreAuthorize("@ss.hasPermi('substation:parameterDetails:list')")
    @GetMapping("/list")
    public TableDataInfo list(SParameterDetails sParameterDetails)
    {
        startPage();
        List<SParameterDetails> list = sParameterDetailsService.list(sParameterDetails.queryWrapper());
        return getDataTable(list);
    }

    /**
     * 获取参数（包含备注）详情列表
     */
    @ApiOperation("获取参数（包含备注）详情列表")
    @PreAuthorize("@ss.hasPermi('substation:parameterDetails:list')")
    @GetMapping("/includeRemarksList")
    public TableDataInfo includeRemarksList(SParameterDetails sParameterDetails)
    {
        startPage();
        List<SParameterDetails> list = sParameterDetailsService.includeRemarksList(sParameterDetails);
        return getDataTable(list);
    }

    /**
     * 导出参数详情列表
     */
    @ApiOperation("导出参数详情列表")
    @PreAuthorize("@ss.hasPermi('substation:parameterDetails:export')")
    @Log(title = "参数详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SParameterDetails sParameterDetails)
    {
        List<SParameterDetails> list = sParameterDetailsService.list(sParameterDetails.queryWrapper());
        ExcelUtil<SParameterDetails> util = new ExcelUtil<SParameterDetails>(SParameterDetails.class);
        util.exportExcel(response, list, "参数详情数据");
    }

    /**
     * 获取参数详情详细信息
     */
    @ApiOperation("获取参数详情详细")
    @ApiImplicitParam(name = "id", value = "参数详情ID", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('substation:parameterDetails:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        SParameterDetails parameterDetails = sParameterDetailsService.getById(id);
        if(StringUtils.isNotNull(parameterDetails)) {
            // 封装备注集合
            SParameterDetailsRemarks remarks = new SParameterDetailsRemarks();
            remarks.setParameterDetailsId(id);
            List<SParameterDetailsRemarks> remarksList = sParameterDetailsRemarksService.getList(remarks);
            parameterDetails.setRemarks(remarksList);
        }
        return success(parameterDetails);
    }

    /**
     * 新增参数详情
     */
    @ApiOperation("新增参数详情")
    @PreAuthorize("@ss.hasPermi('substation:parameterDetails:add')")
    @Log(title = "参数详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SParameterDetails sParameterDetails)
    {
        return toAjax(sParameterDetailsService.save(sParameterDetails));
    }

    /**
     * 修改参数详情
     */
    @ApiOperation("更新参数详情")
    @PreAuthorize("@ss.hasPermi('substation:parameterDetails:edit')")
    @Log(title = "参数详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SParameterDetails sParameterDetails)
    {
        return toAjax(sParameterDetailsService.updateById(sParameterDetails));
    }

    /**
     * 删除参数详情
     */
    @ApiOperation("删除参数详情")
    @ApiImplicitParam(name = "ids", value = "参数详情ID集合", required = true, dataType = "String", paramType = "path")
    @PreAuthorize("@ss.hasPermi('substation:parameterDetails:remove')")
    @Log(title = "参数详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<String> ids)
    {
        return toAjax(sParameterDetailsService.removeByIds(ids));
    }

    /**
     * 查询参数历史版本值
     */
    @ApiOperation("查询参数历史版本值")
    @PreAuthorize("@ss.hasPermi('substation:parameterDetails:list')")
    @GetMapping("/getHistory")
    public AjaxResult getHistory(ParameterDetailsHistoryParamsVo vo)
    {
        List<SParameterDetails> list = sParameterDetailsService.getHistory(vo);
        return success(list);
    }
}
